package com.lmx.repoDomain.tmodel;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.lmx.repoDomain.tmodel.business.User;//huibati

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToOne;

/**
 * 消息类
 */
@Entity
@Table(name = "tnb_message")
@JsonApiResource(type = "message")
public class Message extends BaseEntity {
	private String code;// 编码
	private String business;// 业务类型
	private User fromUser;// 发送人
	private User toUser;// 接收人
	private Short type;// 类型： 0 站内信 1 提醒 4居家消息
	private Short detailType;// 详细类型（提醒类型/站内信类型）
	private Dicttype businessType;// 消息类型
	private String content;// 内容
	private Integer createTime;// 创建时间
	private Integer updateTime;// 更新时间
	private String remark;// 备注
	private Short hasRead;// 是否已读 1是0否
	private Integer num;// 未读条数
	private List<User> userList;// 发送人员列表

	@Column(name = "code")
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "business")
	public String getBusiness() {
		return business;
	}

	public void setBusiness(String business) {
		this.business = business;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@Fetch(FetchMode.JOIN)
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "from_user", foreignKey = @ForeignKey(name = "null"))
	public User getFromUser() {
		return fromUser;
	}

	public void setFromUser(User fromUser) {
		this.fromUser = fromUser;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "to_user", foreignKey = @ForeignKey(name = "null"))
	@Fetch(FetchMode.JOIN)
	public User getToUser() {
		return toUser;
	}

	public void setToUser(User toUser) {
		this.toUser = toUser;
	}

	@Column(name = "type")
	public Short getType() {
		return type;
	}

	public void setType(Short type) {
		this.type = type;
	}

	@Column(name = "detail_type")
	public Short getDetailType() {
		return detailType;
	}

	public void setDetailType(Short detailType) {
		this.detailType = detailType;
	}

	@Column(name = "content", columnDefinition = "TEXT")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "create_time")
	public Integer getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Integer createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Integer getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Integer updateTime) {
		this.updateTime = updateTime;
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "has_read")
	public Short getHasRead() {
		return hasRead;
	}

	public void setHasRead(Short hasRead) {
		this.hasRead = hasRead;
	}

	@Transient
	public Integer getNum() {
		if (num == null) {
			return 0;
		}
		return num;
	}

	public void setNum(Integer num) {
		this.num = num;
	}

	@Transient
	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "business_type", foreignKey = @ForeignKey(name = "null"))
	@Fetch(FetchMode.JOIN)
	public Dicttype getBusinessType() {
		return businessType;
	}

	public void setBusinessType(Dicttype businessType) {
		this.businessType = businessType;
	}

}
